<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <div th:replace="header::common"></div>
    <script type="text/javascript" th:src="@{../static/echarts.min.js}"></script>
    <style>
        .style{
            display: flex;
            flex-wrap: wrap;
        }
    </style>
</head>
<body>
    <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
    <div class="style">
    <div id="main1" style="width: 600px;height:400px;"></div>
    <div id="main2" style="width: 600px;height:400px;"></div>
    </div>
    <script type="text/javascript">
      // 基于准备好的dom，初始化echarts实例
      var myChart1 = echarts.init(document.getElementById('main1'));
      var myChart2 = echarts.init(document.getElementById('main2'));

      $.post(
          '/echarts/selectByCustomIdCount',
          function (result) {
              console.log(result);
              // [{name: 'Java', value: 15},{name: 'UI', value: 2}]
              let xArray = new Array();
              let yArray = new Array();
              let data = result.data;
              for (let i = 0; i < data.length; i++) {
                  xArray.push(data[i].name);
                  yArray.push(data[i].number);
              }
              // 指定图表的配置项和数据
              let option1 = {
                  title: {
                      text: '用户消费次数统计'
                  },
                  tooltip: {},
                  legend: {
                      data: ['消费次数']
                  },
                  xAxis: {
                      data: xArray
                  },
                  yAxis: {},
                  series: [
                      {
                          name: '消费次数',
                          type: 'bar',
                          data: yArray
                      }
                  ]
              };

              // 使用刚指定的配置项和数据显示图表。
              myChart1.setOption(option1);
          },

          'json'
      );
      $.post(
          '/echarts/selectByServiceIdCount',
          function (result){
              console.log(result);
              //{nickname: 'zhao', numble: 1}...
              let xArray=new Array();
              let yArray=new Array();
              let data=result.data;
              for (let i = 0; i < data.length; i++) {
                  xArray.push(data[i].name);
                  yArray.push(data[i].number);
              }
              // 指定图表的配置项和数据
              let option2 = {
                  title: {
                      text: '服务选择次数统计'
                  },
                  tooltip: {},
                  legend: {
                      data: ['服务选择次数']
                  },
                  xAxis: {
                      data:xArray
                  },
                  yAxis: {},
                  series: [
                      {
                          name: '服务选择次数',
                          type: 'bar',
                          data:yArray
                      }
                  ]
              };
              // 使用刚指定的配置项和数据显示图表。
              myChart2.setOption(option2);
          },
          'json'
      );
    </script>
</body>
</html>